/**
 * 
 */
package com.xpec.c4.game.login.async2;

import com.ms.service.module.account.Account;
import com.xpec.c4.game.login.LoginModule;
import com.xpec.c4.game.utility.GUID;
import com.xpec.c4.message.MessageTypes;
import com.xpec.c4.message.character.SCheckPlayerLoginLockInfo;
import com.xpec.c4.message.login.CAccountCharacterLoginRequest;
import com.xpec.c4.service.group.transportlayer.GroupMessage;
import com.xpec.c4.service.message.MessageAction;
import com.xpec.c4.service.module.ModuleName;
import com.xpec.c4.service.module.common.PlayerCommonInfoManager;
import com.xpec.c4.service.module.gateway.SetSessionStatus;

/**
 * @author TW15010
 *
 */
public class CharacterLoginGetAccountAsync extends DoAfterLoadAccountAsync {
	private GUID sessionID;

	private GUID accountID;

	private CAccountCharacterLoginRequest message;

	@Override
	public void execute() throws Exception {
		LoginModule module = (LoginModule) getCurrentModuleServer();

		Account account = module.characterBeforeLoginCheckProc(getLoadAccount(), message.playerGuid, accountID,
				sessionID, message.recontoken, SCheckPlayerLoginLockInfo.REQUEST_TYPE_CHARACTER_LOGIN);

		if (account == null) {
			// 前一個lock還未到期
			return;
		}

		// 向Gateway說明, player當前的狀態.
		SetSessionStatus data = new SetSessionStatus();
		data.guid = sessionID;
		// 先定義一個非0的數值
		data.status = SetSessionStatus.READY;

		GroupMessage msg = new GroupMessage();
		msg.setMessageType(MessageTypes.S_SET_GATEWAY_SESSION);
		msg.setMessageContent(data);
		String moduleId = PlayerCommonInfoManager.getInstance().getGatewayBySessionId(sessionID);
		msg.setDestModuleID((moduleId != null) ? moduleId : ModuleName.GATEWAY);
		MessageAction.sendGroupMessage(msg);
	}

	public void setSessionID(GUID sessionID) {
		this.sessionID = sessionID;
	}

	public void setAccountID(GUID accountID) {
		this.accountID = accountID;
	}

	public void setMessage(CAccountCharacterLoginRequest message) {
		this.message = message;
	}
}
